package com.demo.controller;

import com.demo.entity.Class;
import com.demo.entity.ClassExample;
import com.demo.repository.ClassRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller

public class ClassController {
    @Autowired
    ClassRepository classRepository;
    @RequestMapping("/getClassList")
    @ResponseBody
    public List<Class> select(Model model){
        ClassExample classExample=new ClassExample();
        classExample.createCriteria();
        List<Class> classes = classRepository.selectByExample(classExample);
        model.addAttribute("class",classes);
        return classes;
    }
    @RequestMapping("/getSeasonList")
    @ResponseBody
    public List<String> selectSeason(){
        List<String> list=new ArrayList<>();
        list.add("2017-01");
        list.add("2017-02");
        list.add("2018-02");
        list.add("2018-02");
        list.add("2019-01");
        list.add("2019-02");
        return list;
    }
    @RequestMapping("/insertClass")
    @ResponseBody
    public String insert(Class calsses){
        classRepository.insertSelective(calsses);
        return "插入成功";
    }


}
